package com.nervenets.web.hibernate.domain.user;

import com.nervenets.utils.StringUtils;
import com.nervenets.web.enumeration.AuthStatus;
import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.enumeration.Role;
import com.nervenets.web.hibernate.DomainObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 用户类
 * Created by Joe on 2018/1/3.
 */
@Entity
@Table(name = "users")
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User extends DomainObject {
    @Index(name = "_idx_u_mobile")
    private String mobile;
    private String password;
    @Type(type = "com.nervenets.web.adapter.jsonType.UserRoleJson")
    private UserRole role = new UserRole();
    @Index(name = "_idx_u_we_chat_id")
    private String wechatId;
    @Index(name = "_idx_u_we_chat_union_id")
    private String unionId;
    private String avatar;
    private String code = StringUtils.randomUpperString(6);
    private long inviteUserId = 0;
    private long teamUserId = 0;
    @Column(columnDefinition = "tinyint")
    private Gender gender = Gender.male;
    private int birthday;
    private int areaId = 0;//位置ID
    private int disable = 0;//禁用时间
    private int authTime = 0;//认证时间
    private boolean special = false;
    @Column(columnDefinition = "tinyint")
    private AuthStatus authStatus = AuthStatus.init;
    @Type(type = "com.nervenets.web.adapter.jsonType.UserInfoJson")
    private UserInfo info = new UserInfo();

    public User(String mobile, String password) {
        this.mobile = mobile;
        this.password = password;
    }
}
